#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :page_login.py
# @Time      :2021/8/2 14:14
# @author    :Harry
from selenium import webdriver
from selenium.webdriver.common.by import By


class PageLogin():
    def __init__(self, driver):
        self.driver = driver
        # 定位器 locator
        self.loc_ele_login_username = (By.NAME, 'username')   # 用户名输入框
        self.loc_ele_login_password = (By.NAME, 'password')  # 密码输入框
        self.loc_ele_login_submit = (By.NAME, 'submit')      # 立即登录按钮
        self.loc_assert_login = (By.XPATH, '//font[@id="ECS_MEMBERZONE"]/a[1]')  # 断言登录后的用户名

    def ele_login_username(self,username):
        '''登录用户名'''
        self.driver.find_element(*self.loc_ele_login_username).send_keys(username)   # 传递元组数据要结构

    def ele_login_password(self,password):
        '''登录密码'''
        self.driver.find_element(*self.loc_ele_login_password).send_keys(password)

    def ele_login_submit(self):
        '''登录提交按钮'''
        self.driver.find_element(*self.loc_ele_login_submit).click()

    def assert_login(self):
        '''断言登陆后的用户名'''
        actual_result = self.driver.find_element(*self.loc_assert_login).text
        return actual_result

    def login(self,username,password):
        '''封装登录逻辑'''
        self.ele_login_username(username)
        self.ele_login_password(password)
        self.ele_login_submit()
        return self.assert_login()
